This notebook can be used to generate tradeoff values from all the Pareto-optimal data point files hard-coded in the dictionary pfs. Currently this notebook processes these Pareto-optimal fronts.
%matplotlib notebook
%reload_ext autoreload
%autoreload 2
import sys
import os
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm as cm
import matplotlib.colors as mc
from mpl_toolkits.mplot3d import Axes3D
plt.rcParams.update({'figure.max_open_warning': 0})
We generate and plot at the same time. The $\mu$ values will be saved in the same corresponding directories where the objective values are read from. During the plotting, will change the point size w.r.t. $\mu$ values. For coloring, we will use default color for non-constrained problems and use cm.cool for problems with constraint functions. The knee points will be colored as dark red.
sys.path.append('../src')
from utils import dm
pfs = {'dtlz2': ['3d', '4d', '8d'], \
'dtlz2-nbi': ['3d', '4d', '8d'], \
'debmdk': ['3d', '4d', '8d'], \
'debmdk-nbi': ['3d', '4d', '8d'], \
'debmdk-all': ['3d', '4d', '8d'], \
'debmdk-all-nbi': ['3d', '4d', '8d'], \
'dtlz8': ['3d', '4d', '6d', '8d'], \
'dtlz8-nbi': ['3d', '4d', '6d', '8d'], \
'c2dtlz2': ['3d', '4d', '5d', '8d'], \
'c2dtlz2-nbi': ['3d', '4d', '5d', '8d'], \
'cdebmdk': ['3d', '4d', '8d'], \
'cdebmdk-nbi': ['3d', '4d', '8d'], \
'c0dtlz2': ['3d', '4d', '8d'], \
'c0dtlz2-nbi': ['3d', '4d', '8d'], \
'gaa': ['10d'], \
'gaa-nbi': ['10d']}
eps = {'3d': 0.125, '4d': 0.125, '5d': 0.125, '6d': 0.25, '8d': 0.25}
for pf in pfs:
fig = plt.figure(figsize = (9, 3), constrained_layout = True)
c = len(pfs[pf])
c_ = 1
for dim in pfs[pf]:
fullpathf = "../data/{0:s}/{1:s}/dataf.csv".format(pf, dim)
if os.path.exists(fullpathf):
path, filenamef = os.path.split(fullpathf)
dirs = path.split('/')
frontname = dirs[-2]
F = np.loadtxt(fullpathf, delimiter = ',')
print(fullpathf, F.shape, dirs, frontname)
Mu,Ik = dm.tradeoff(F, epsilon = eps[dim], penalize_extremes = False)
mupathf = os.path.join(path, "mu.csv")
np.savetxt(mupathf, Mu, delimiter = ',', fmt = "%1.4e")
muidxpathf = os.path.join(path, "muid.csv")
np.savetxt(muidxpathf, Ik, delimiter = ',', fmt = "%d")
In = np.arange(0, F.shape[0]).astype(int)
Ip = np.delete(In, Ik)
# change size w.r.t. Mu
Sp = (Mu[Ip] + 0.1) * 30.0
# knee points are the biggest
Sk = (Mu[Ik] + 0.1) * 75.0
# load CV if exists, use it for coloring
cvpathf = os.path.join(path, "datacv.csv")
Cp = np.array([mc.to_rgba(mc.TABLEAU_COLORS['tab:blue'], 0.5) for _ in range(Ip.shape[0])])
if os.path.exists(cvpathf):
CV = np.loadtxt(cvpathf, delimiter = ',')
Cp = np.array([mc.to_rgba(cm.cool(v * 0.75), 0.5) for v in CV[Ip]])
# the knees will have red color
Ck = np.array([mc.to_rgba(mc.TABLEAU_COLORS['tab:red'], 1.0) for _ in range(Ik.shape[0])])
# plot
ax = fig.add_subplot(1, c, c_, projection = '3d')
# original points, dividing by 5 because
# the plots are too small and matplotlib
# adjusts the point size according to plot size
ax.scatter(F[Ip,0], F[Ip,1], F[Ip,2], color = Cp, s = Sp / 5)
# knee points, same here
ax.scatter(F[Ik,0], F[Ik,1], F[Ik,2], color = Ck, s = Sk / 5)
c_ = c_ + 1
else:
print("Error: {:s} not found.".format(fullpathf))
plt.show()